package com.ruitu.health_2.mvp.presenter;

import com.ruitu.arad.base.BasePresenter;
import com.ruitu.arad.util.ToastUtils;
import com.ruitu.health_2.mvp.model.ArtManModel;
import com.ruitu.health_2.ui.activity.ArtManDetailActivity;
import com.ruitu.health_2.ui.activity.ArtManListActivity;
import com.ruitu.router_module.bean.BaseResult2;
import com.ruitu.router_module.bean.PageModel2;
import com.ruitu.router_module.bean.product.ArtMan;
import com.ruitu.router_module.bean.product.ArtManDetail;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

public class ArtManPresenter {

    public static class ArtManListP extends BasePresenter<ArtManListActivity, ArtManModel.ArtManListM> {

        public Disposable reqArtManListByName(int size, int num, String title) {
            return m.reqArtManListByName(size, num, title).subscribe(new Consumer<BaseResult2<PageModel2<ArtMan>>>() {
                @Override
                public void accept(BaseResult2<PageModel2<ArtMan>> baseResult) throws Exception {
                    v.hideProgress();
                    if (baseResult.isSuccess()) {
                        v.onReqComplete(1, true, baseResult.getData());
                    } else {
                        ToastUtils.showShortSafe(baseResult.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    throwable.printStackTrace();
                    v.hideProgress();
                }
            });
        }
    }

    public static class ArtManDetailP extends BasePresenter<ArtManDetailActivity, ArtManModel.ArtManDetailM> {
        public Disposable reqArtManDetail(String artId) {
            return m.reqArtManDetail(artId).subscribe(new Consumer<BaseResult2<ArtManDetail>>() {
                @Override
                public void accept(BaseResult2<ArtManDetail> result) throws Exception {
                    v.hideProgress();
                    if (result.isSuccess()){
                        v.onReqComplete(1,true,result.getData());
                    }else {
                        ToastUtils.showShortSafe(result.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    throwable.printStackTrace();
                    v.hideProgress();
                }
            });
        }
    }
}
